<template>
  <div class="project-management-container">
    <!-- 搜索表单 -->
    <el-form :inline="true" :model="searchForm" class="compact-form">
      <el-form-item label="开始时间">
        <el-date-picker v-model="searchForm.startTime" type="datetime" placeholder="请选择开始时间" size="small" />
      </el-form-item>
      <el-form-item label="结束时间">
        <el-date-picker v-model="searchForm.endTime" type="datetime" placeholder="请选择结束时间" size="small" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="small" @click="handleSearch">查询</el-button>
      </el-form-item>
    </el-form>

    <!-- 数据表格 -->
    <vxe-table border show-overflow :data="tableData" size="mini" height="600" class="compact-table">
      <vxe-column type="seq" title="序号" width="60" align="center" />
      <vxe-column field="pressure" title="压力 (Pa)" />
      <vxe-column field="material" title="物料类型" />
      <vxe-column field="temperature" title="温度 (°C)" />
      <vxe-column field="flowRate" title="流量 (m³/h)" />
      <vxe-column field="power" title="功率 (kW)" />
      <vxe-column field="vibration" title="振动 (mm/s)" />
      <vxe-column field="speed" title="转速 (rpm)" />
      <vxe-column field="phLevel" title="pH值" />
      <vxe-column field="humidity" title="湿度 (%)" />
      <vxe-column field="voltage" title="电压 (V)" />
      <vxe-column field="current" title="电流 (A)" />
      <vxe-column field="efficiency" title="效率 (%)" />
      <vxe-column field="fuelConsumption" title="燃料消耗 (kg/h)" />
      <vxe-column field="maintenanceStatus" title="维护状态" />
      <vxe-column field="noiseLevel" title="噪音水平 (dB)" />
      <vxe-column field="timestamp" title="时间戳" width="160" />
    </vxe-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      searchForm: {
        startTime: null,
        endTime: null
      },
      tableData: []
    };
  },
  methods: {
    // 生成假数据
    generateFakeData() {
      const materials = ["石灰石", "活性炭", "氨水", "水"];
      const randomInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
      const randomFloat = (min, max, decimals) => (Math.random() * (max - min) + min).toFixed(decimals);
      const randomBool = () => Math.random() < 0.5;
      const randomEnum = (arr) => arr[Math.floor(Math.random() * arr.length)];

      const fakeData = [];

      for (let i = 0; i < 30; i++) {
        fakeData.push({
          pressure: randomInt(1000, 5000),
          material: materials[randomInt(0, materials.length - 1)],
          temperature: randomFloat(20, 100, 2),
          flowRate: randomFloat(50, 200, 2),
          power: randomFloat(10, 50, 2),
          vibration: randomFloat(0, 5, 2),
          speed: randomInt(1000, 3000),
          phLevel: randomFloat(4, 12, 2),
          humidity: randomFloat(20, 100, 2),
          voltage: randomFloat(200, 400, 2),
          current: randomFloat(5, 50, 2),
          efficiency: randomFloat(80, 100, 2),
          fuelConsumption: randomFloat(10, 30, 2),
          maintenanceStatus: randomEnum(["正常", "待检修", "维修中"]),
          noiseLevel: randomFloat(60, 90, 2),
          timestamp: new Date(Date.now() - (30 - i) * 1000).toISOString() // 每秒一条数据
        });
      }

      this.tableData = fakeData;
    },

    // 查询操作
    handleSearch() {
      // 模拟查询数据
      this.generateFakeData();
    }
  },

  mounted() {
    // 初始加载时生成假数据
    this.generateFakeData();
  }
};
</script>

<style scoped>
.project-management-container {
  padding: 20px;
}

.compact-form {
  margin-bottom: 20px;
}

.compact-table {
  margin-top: 20px;
}

.drawer-footer {
  text-align: right;
  margin-top: 20px;
}
</style>
